furny.ga.util
Class FurnitureUtil

java.lang.Object
  extended by furny.ga.util.FurnitureUtil

public final class FurnitureUtil
extends java.lang.Object

Utility class for handling furniture similarities.

Since:
11.08.2012
Author:
Stephan Dreyer

Nested Class Summary
private static class FurnitureUtil.FurniturePair
          Sorted pair for caching similarities.
 
Field Summary
private static java.util.logging.Logger LOGGER
           
private static java.util.Map<FurnitureUtil.FurniturePair,java.lang.Double> SIMILARITY_MAP
          This map caches all distance calculations, so they are reusable.
 
Constructor Summary
private FurnitureUtil()
          Instantiation is not allowed.
 
Method Summary
private static
<T extends java.lang.Comparable<T>>
java.util.Map<Furniture,T>
createSortedMap(java.util.Map<Furniture,T> passedMap)
          Creates a descending sorted map from the given map.
static float getCosts(FurnLayoutIndividual ind)
          Calculates the total costs of a furniture layout.
private static double getManhattanDistance(double w1, double w2, double l1, double l2)
          Calculates the manhattan distance of width and length.
static Furniture getOtherFurnitureBySimilarityDistance(Furniture f1, int dist)
          Gets the furniture with a distance inside of the given width.
static Furniture getOtherFurnitureBySimilarityRoulette(Furniture f1)
          This method does a roulette selection on the sorted map of similarities (rank map) to find a second furniture.
static double getSimilarity(Furniture furn1, Furniture furn2)
          Calculates the similarity between two furnitures by their tags.
private static double getSimilarityImpl(Furniture furn1, Furniture furn2)
          Calculates the similarity between two furnitures by their tags.
static java.util.Map<Furniture,java.lang.Double> getSimilarityRankMap(Furniture furn1, java.util.List<Furniture> allFurnitures)
          Creates a sorted map of furnitures and their similarities to the given furniture.
private static double getTagSimilarity(Furniture furn1, Furniture furn2)
          Calculates the similarity between two sets of tags.
static void main(java.lang.String[] args)
          Main method for test purposes.
private static Furniture rouletteImpl(java.util.Map<Furniture,java.lang.Double> map)
          Roulette algorithm for maps.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

SIMILARITY_MAP

private static final java.util.Map<FurnitureUtil.FurniturePair,java.lang.Double> SIMILARITY_MAP
This map caches all distance calculations, so they are reusable.

Constructor Detail

FurnitureUtil

private FurnitureUtil()
Instantiation is not allowed.

Since:
11.08.2012
Method Detail

getSimilarity

public static double getSimilarity(Furniture furn1,
                                   Furniture furn2)
Calculates the similarity between two furnitures by their tags. This method caches the results.

Parameters:
furn1 - The first furniture.
furn2 - The second furniture.
Returns:
The similarity in [0;1].
Since:
11.08.2012
See Also:
getSimilarityImpl(Furniture, Furniture)

getSimilarityImpl

private static double getSimilarityImpl(Furniture furn1,
                                        Furniture furn2)
Calculates the similarity between two furnitures by their tags.

Parameters:
furn1 - The first furniture.
furn2 - The second furniture.
Returns:
The similarity in [0;1].
Since:
11.08.2012
See Also:
getSimilarity(Furniture, Furniture)

getManhattanDistance

private static double getManhattanDistance(double w1,
                                           double w2,
                                           double l1,
                                           double l2)
Calculates the manhattan distance of width and length.

Parameters:
w1 - Width 1
w2 - Width 2
l1 - Length 1
l2 - Length 2
Returns:
Manhattan distance.
Since:
11.08.2012

getTagSimilarity

private static double getTagSimilarity(Furniture furn1,
                                       Furniture furn2)
Calculates the similarity between two sets of tags.

Parameters:
furn1 - The first furniture.
furn2 - The second furniture.
Returns:
The similarity in [0;1].
Since:
11.08.2012
See Also:
getSimilarity(Furniture, Furniture)

getSimilarityRankMap

public static java.util.Map<Furniture,java.lang.Double> getSimilarityRankMap(Furniture furn1,
                                                                             java.util.List<Furniture> allFurnitures)
Creates a sorted map of furnitures and their similarities to the given furniture.

Parameters:
furn1 - The furniture to calculate similarities for.
allFurnitures - All other furnitures.
Returns:
Map of Furnitures and similarities sorted by their similarities.
Since:
11.08.2012

createSortedMap

private static <T extends java.lang.Comparable<T>> java.util.Map<Furniture,T> createSortedMap(java.util.Map<Furniture,T> passedMap)
Creates a descending sorted map from the given map.

Type Parameters:
T - Generic type parameter
Parameters:
passedMap - The map to create the sorted map from.
Returns:
The sorted map.
Since:
11.08.2012

getOtherFurnitureBySimilarityRoulette

public static Furniture getOtherFurnitureBySimilarityRoulette(Furniture f1)
This method does a roulette selection on the sorted map of similarities (rank map) to find a second furniture.

Parameters:
f1 - Furniture
Returns:
A furniture with a high similarity to the first one.
Since:
11.08.2012

getOtherFurnitureBySimilarityDistance

public static Furniture getOtherFurnitureBySimilarityDistance(Furniture f1,
                                                              int dist)
Gets the furniture with a distance inside of the given width.

Parameters:
f1 - The furniture.
dist - The width where the other furniture should be inside.
Returns:
The other furniture.
Since:
11.08.2012

rouletteImpl

private static Furniture rouletteImpl(java.util.Map<Furniture,java.lang.Double> map)
Roulette algorithm for maps. Adapted from Stack overflow.

Parameters:
map - The map of furnitures and similarities.
Returns:
The selected furniture.
Since:
11.08.2012

getCosts

public static float getCosts(FurnLayoutIndividual ind)
Calculates the total costs of a furniture layout.

Parameters:
ind - The individual.
Returns:
The total cost.
Since:
11.08.2012

main

public static void main(java.lang.String[] args)
Main method for test purposes.

Parameters:
args - No arguments.
Since:
11.08.2012